package xin.marcher.module.quality.config;

import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.context.annotation.Bean;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;
import xin.marcher.module.rights.api.LoginApi;
import xin.marcher.module.rights.support.PermissionSupport;

@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {

    @DubboReference(version = "1.0.0")
    private LoginApi loginApi;

    @Bean("rights")
    public PermissionSupport check() {
        return new PermissionSupport(loginApi);
    }

    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
    }
}